package com.bugman.managed;

import com.bugman.business.BugService;
import com.bugman.business.ProjectService;
import com.bugman.entity.Bug;
import com.bugman.entity.Project;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;

/**
 *
 * @author Ediczech
 */
public class ProjectBugsBean extends BaseBean {

    final private Integer COUNT = 20;
    private String projectId;
    private List<Bug> bugs;
    private Project project = new Project();
    @EJB
    ProjectService projectService;
    @EJB
    BugService bugService;

    @PostConstruct
    public void init() {
        projectId = getRequestParameter("id");
        if (projectId != null) {
            project = projectService.getProject(Integer.valueOf(projectId));
            logger.info("Loaded project: " + project.getName());
            bugs = bugService.getLatestBugs(project, COUNT);
        } else {
            //TODO for Ediczech: stop loading page
        }
    }

    public boolean isIsAnyBug() {
        if (bugService.getBugsCount(project) == 0) {
            return false;
        } else {
            return true;
        }
    }

    public List<Bug> getBugs() {
        return bugs;
    }

    public void setBugs(List<Bug> bugs) {
        this.bugs = bugs;
    }

    public Project getProject() {
        return project;
    }

    public void setProject(Project project) {
        this.project = project;
    }
}